package com.nari.ies.ne.nw.server.service.fileScore.impl;

import com.nari.ies.ne.nw.server.entity.PvFileScoreEntity;
import com.nari.ies.ne.nw.server.entity.WindFileScoreEntity;
import com.nari.ies.ne.nw.server.mapper.FileScoreMapper;
import com.nari.ies.ne.nw.server.service.fileScore.IFileScoreService;
import com.nari.ies.ne.nw.server.service.fileScore.ISYZXXFileScoreService;
import com.nari.ies.ne.nw.server.util.DataUtil;
import com.nari.ies.ne.nw.server.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class SYZXXFileScoreServiceImpl implements ISYZXXFileScoreService {
    @Autowired
    private IFileScoreService fileScoreService;
    @Autowired
    private FileScoreMapper fileScoreMapper;
    @Override
    public WindFileScoreEntity FDSYZXXFileScore(WindFileScoreEntity windFileScoreEntity) {

        String plantId = windFileScoreEntity.getPlantId();
        //今天00:00
        Date endDate = windFileScoreEntity.getDateTime();
        Date startDate = DateUtil.getYesterdayTime(endDate);
        String fileType = "SYZXX";
        String plantType = "FD";
        String tableName = "HISDB.NW_NE_FILE_DATACHECK_FD_SYZXX";

        //上送文件数量
        int SYZXXNum = fileScoreMapper.selectFileNumData(tableName,plantId, fileType, plantType, startDate, endDate);
        //文件满分
        float SYZXXFullScore = fileScoreMapper.selectFileFullScore(fileType, plantType);
        //完整率
        float SYZXXRate = 0;
        //文件上送率
        float SYZXXSendRate = 0;
        //文件得分
        float SYZXXScore = 0;
        //文件合格率
        float SYZXXQualifiedRate = 0;


        if (SYZXXNum > 0) {
            SYZXXSendRate = 100;
            //完整率
            SYZXXRate = (float) SYZXXNum / 96 * 100;
            //文件数据项总得分
            float fileDataScore = fileScoreService.getFileDataScore(plantId, fileType, plantType, startDate, endDate,tableName);
            //文件得分
            SYZXXScore = fileDataScore ;
            //文件合格率
            SYZXXQualifiedRate = SYZXXScore / SYZXXFullScore * 100;

        }else {
            SYZXXRate=0;
            SYZXXScore=0;
            SYZXXSendRate=0;
            SYZXXQualifiedRate= 0;
        }
        windFileScoreEntity.setSYZXXNum(SYZXXNum);
        windFileScoreEntity.setSYZXXRate(SYZXXRate);
        windFileScoreEntity.setSYZXXScore(SYZXXScore);
        windFileScoreEntity.setSYZXXFullScore(SYZXXFullScore);
        windFileScoreEntity.setSYZXXSendRate(SYZXXSendRate);
        windFileScoreEntity.setSYZXXQualifiedRate(SYZXXQualifiedRate);

        return windFileScoreEntity;
    }

    @Override
    public PvFileScoreEntity GFSYZXXFileScore(PvFileScoreEntity pvFileScoreEntity) {
        String plantId = pvFileScoreEntity.getPlantId();
        //今天00:00
        Date endDate = pvFileScoreEntity.getDateTime();
        Date startDate = DateUtil.getYesterdayTime(endDate);
        String fileType = "SYZXX";
        String plantType = "GF";
        String tableName="HISDB.NW_NE_FILE_DATACHECK_GF_SYZXX";

        //上送文件数量
        int SYZXXNum = fileScoreMapper.selectFileNumData(tableName,plantId, fileType, plantType, startDate, endDate);
        //文件满分
        float SYZXXFullScore = fileScoreMapper.selectFileFullScore(fileType, plantType);
        //完整率
        float SYZXXRate = 0;
        //文件上送率
        float SYZXXSendRate = 0;
        //文件得分
        float SYZXXScore = 0;
        //文件合格率
        float SYZXXQualifiedRate = 0;


        if (SYZXXNum > 0) {
            SYZXXSendRate = 100;
            //完整率
            SYZXXRate = (float) SYZXXNum / 96 * 100;
            //文件数据项总得分
            float fileDataScore = fileScoreService.getFileDataScore(plantId, fileType, plantType, startDate, endDate,tableName);
            //文件得分
            SYZXXScore =fileDataScore;
            //文件合格率
            SYZXXQualifiedRate = SYZXXScore / SYZXXFullScore * 100;
        }else {
            SYZXXRate=0;
            SYZXXScore=0;
            SYZXXSendRate=0;
            SYZXXQualifiedRate= 0;
        }
        pvFileScoreEntity.setSYZXXNum(SYZXXNum);
        pvFileScoreEntity.setSYZXXRate(SYZXXRate);
        pvFileScoreEntity.setSYZXXScore(SYZXXScore);
        pvFileScoreEntity.setSYZXXFullScore(SYZXXFullScore);
        pvFileScoreEntity.setSYZXXQualifiedRate(SYZXXSendRate);
        pvFileScoreEntity.setSYZXXSendRate(SYZXXQualifiedRate);

        return pvFileScoreEntity;
    }



}
